from abaqus import *
from abaqusConstants import *
from caeModules import *
from driverUtils import executeOnCaeStartup
from textRepr import*
mdb=openMdb(pathName='E:/temp/couple_py/couple.cae')
a=mdb.models['Model-1'].rootAssembly
ins=a.instances
part=[]
for ii in range(6):
	iii=ii+1
	part_name='couple-'+str(iii)+'-1'
	p=a.instances[part_name]
	part.append(p)

edges=part[0].edges
edges_1=part[0].edges
set=a.sets
set_test=set['set_test']
coord1=set_test.vertices.pointsOn[0][0]
coord2=(set_test.vertices.pointsOn[0][0][0],set_test.vertices.pointsOn[0][0][1],set_test.vertices.pointsOn[0][0][2]-100)
ee=edges_1.getByBoundingCylinder(center1=coord1,center2=coord2,radius=5)
mid1=part[0].InterestingPoint(edge=ee[0],rule=MIDDLE)
vertex=part[0].vertices
vv=vertex.getByBoundingCylinder(center1=coord1,center2=coord2,radius=5)
datum1=a.DatumPointByMidPoint(point1=vv[0], point2=mid1)

mid2=part[0].InterestingPoint(edge=ee[1],rule=MIDDLE)
datum2=a.DatumPointByMidPoint(point1=vv[1], point2=mid2)

a = mdb.models['Model-1'].rootAssembly
datums=a.datums
datum_ref=a.DatumPointByMidPoint(point1=datums[datum1.id], point2=datums[datum2.id])

a = mdb.models['Model-1'].rootAssembly
datums=a.datums
ref=a.ReferencePoint(point=datums[datum_ref.id])